﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Quotation.aspx.cs" Inherits="SalesManagement.Modules.Sales.Quotation" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script language="javascript" type="text/javascript">
        function DocumentReady() {
            var obj = document.getElementById('ResourceManager');
            MethodNamespace.DocumentReady({
                success: function() {

                }
            });
        }
    </script>

    <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var add = function () {
                var grid = #{GridPanel1};
                grid.getRowEditor().stopEditing();
                
                grid.insertRecord(0, {

                });
                
                grid.getView().refresh();
                grid.getSelectionModel().selectRow(0);
                grid.getRowEditor().startEditing(0);
            }
            
            var remove = function () {
                var grid = #{GridPanel1};
                grid.getRowEditor().stopEditing();
                
                var s = grid.getSelectionModel().getSelections();
                
                for (var i = 0, r; r = s[i]; i++) {
                    #{storeQuotationDetail}.remove(r);
                }
            }
        </script>
    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager" runat="server" DirectMethodNamespace="MethodNamespace">
        <Listeners>
            <DocumentReady Handler="DocumentReady();" Delay="100" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="storeBranch" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="BranchId">
                <Fields>
                    <ext:RecordField Name="BranchId" /> 
                    <ext:RecordField Name="BranchName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="storeQuotationDetail" runat="server" RemoteSort="true">
        <Reader>
            <ext:JsonReader IDProperty="QuotationDetailId">
                <Fields>
                    <ext:RecordField Name="QuotationDetailId" />
                    <ext:RecordField Name="QuotationId" />
                    <ext:RecordField Name="ProductId" />
                    <ext:RecordField Name="UnitId" />
                    <ext:RecordField Name="UnitPrice" />
                    <ext:RecordField Name="Deleted" />
                    <ext:RecordField Name="CreatedDate" />
                    <ext:RecordField Name="CreatedBy" />
                    <ext:RecordField Name="UpdatedDate" />
                    <ext:RecordField Name="UpdatedBy" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="storeProduct" runat="server" RemoteSort="true">
        <Reader>
            <ext:JsonReader IDProperty="ProductId">
                <Fields>
                    <ext:RecordField Name="ProductId" />
                    <ext:RecordField Name="ProductCode" />
                    <ext:RecordField Name="ProductName" />
                    <ext:RecordField Name="CategoryId" />
                    <ext:RecordField Name="OutUnit" />
                    <ext:RecordField Name="InputUnit" />
                    <ext:RecordField Name="StockUnit" />
                    <ext:RecordField Name="OutputPrice" />
                    <ext:RecordField Name="InputPrice" />
                    <ext:RecordField Name="StockPrice" />
                    <ext:RecordField Name="Description" />
                    <ext:RecordField Name="IsWarranty" />
                    <ext:RecordField Name="IsActive" />
                    <ext:RecordField Name="CreatedDate" />
                    <ext:RecordField Name="CreatedBy" />
                    <ext:RecordField Name="UpdatedDate" />
                    <ext:RecordField Name="UpdatedBy" />
                    <ext:RecordField Name="MinStock" />
                    <ext:RecordField Name="MaxStock" />
                    <ext:RecordField Name="WarehouseId" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Height="185" Border="false" Region="North"
                Split="true" BodyStyle="background-color:transparent;">
                <Items>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnNew" runat="server" Icon="PageAdd" Text="Tạo mới">
                            </ext:Button>
                            <ext:Button ID="Button3" runat="server" Icon="Disk" Text="Lưu" Disabled="true">
                            </ext:Button>
                            <ext:Button ID="btnCancel" runat="server" Icon="Cancel" Text="Bỏ qua">
                            </ext:Button>
                            <ext:Button ID="btnDelete" runat="server" Icon="Delete" Text="Xóa">
                            </ext:Button>
                            <ext:Button ID="btnPrinter" runat="server" Text="In" Icon="Printer" Disabled="false">
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                    <ext:FormPanel ID="FormPanel1" runat="server" Padding="5" Border="false" BodyStyle="background-color:transparent;"
                        Layout="FormLayout">
                        <Items>
                            <ext:Panel BodyStyle="background-color:transparent;" Border="false" Layout="ColumnLayout"
                                Padding="2">
                                <Items>
                                    <ext:Panel ID="Panel3" runat="server" Layout="FormLayout" ColumnWidth=".333333" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:TextField ID="txtQuotationNo" runat="server" FieldLabel="Mã phiếu" AnchorHorizontal="93%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:Panel ID="Panel7" runat="server" Layout="FormLayout" ColumnWidth=".333333" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:DateField ID="dfQuotationDate" runat="server" FieldLabel="Ngày" AnchorHorizontal="93%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:Container ID="Container1" runat="server" ColumnWidth=".333333">
                                        <Items>
                                            <ext:Checkbox ID="ckbIsActive" runat="server" FieldLabel="Kích hoạt">
                                            </ext:Checkbox>
                                        </Items>
                                    </ext:Container>
                                    <ext:DateField ID="DateField1" runat="server" ColumnWidth=".3" />
                                </Items>
                            </ext:Panel>
                            <ext:Panel BodyStyle="background-color:transparent;" Border="false" Layout="ColumnLayout"
                                Padding="2">
                                <Items>
                                    <ext:Panel ID="Panel2" runat="server" Layout="FormLayout" ColumnWidth=".333333" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:ComboBox ID="cbbGroupId" runat="server" FieldLabel="Nhóm đối tượng" AnchorHorizontal="93%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:Panel ID="Panel4" runat="server" Layout="FormLayout" ColumnWidth=".333333" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:ComboBox ID="cbBranchId" runat="server" FieldLabel="Chi nhánh" AnchorHorizontal="93%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:ComboBox ID="cbbEmployeeId" runat="server" FieldLabel="Nhân viên" AnchorHorizontal="93%"
                                        ColumnWidth=".3" />
                                </Items>
                            </ext:Panel>
                            <ext:Panel BodyStyle="background-color:transparent;" Border="false" Layout="ColumnLayout"
                                Padding="2">
                                <Items>
                                    <ext:Panel ID="Panel5" runat="server" Layout="FormLayout" ColumnWidth=".333333" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:ComboBox ID="cbbObjectId" runat="server" FieldLabel="Mã Đối tượng" AnchorHorizontal="93%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:Panel ID="Panel8" runat="server" Layout="FormLayout" ColumnWidth=".333333" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:ComboBox ID="cbbObjectName" runat="server" FieldLabel="Tên Đối tượng" AnchorHorizontal="93%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:TextField ID="txtContactName" runat="server" FieldLabel="Tên liên hệ" ColumnWidth=".333333"
                                        AnchorHorizontal="93%" />
                                </Items>
                            </ext:Panel>
                            <ext:Panel BodyStyle="background-color:transparent;" Border="false" Layout="ColumnLayout"
                                Padding="2">
                                <Items>
                                    <ext:Panel ID="Panel6" runat="server" Layout="FormLayout" ColumnWidth=".666666" BodyStyle="background-color:transparent;"
                                        Border="false">
                                        <Items>
                                            <ext:TextField ID="txtAddress" runat="server" FieldLabel="Địa chỉ" AnchorHorizontal="96.5%" />
                                        </Items>
                                    </ext:Panel>
                                    <ext:TextField ID="txtPhone" runat="server" FieldLabel="Di động" ColumnWidth=".333333" />
                                </Items>
                            </ext:Panel>
                            <ext:Panel BodyStyle="background-color:transparent;" Border="false" Layout="ColumnLayout"
                                Padding="2">
                                <Items>
                                    <ext:Checkbox ID="Checkbox1" runat="server" FieldLabel="Khách hàng">
                                    </ext:Checkbox>
                                    <ext:Checkbox ID="Checkbox2" runat="server" FieldLabel="Nhà cung cấp">
                                    </ext:Checkbox>
                                </Items>
                            </ext:Panel>
                            <ext:Panel BodyStyle="background-color:transparent;" Border="false" Layout="ColumnLayout"
                                Padding="2">
                                <Items>
                                    <ext:Checkbox ID="Checkbox3" runat="server" FieldLabel="Lấy tất cả">
                                    </ext:Checkbox>
                                    <ext:Checkbox ID="Checkbox4" runat="server" FieldLabel="Hàng chợ">
                                    </ext:Checkbox>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:FormPanel>
                </Items>
            </ext:Panel>
            <%--<ext:Panel ID="Panel9" runat="server" Layout="Fit" Region="Center" Border="false">
                <Items>
                    <ext:GridPanel ID="GridPanel1" runat="server" Height="300" StoreID="storeQuotationDetail" ColumnLines="true">
                        <ColumnModel ID="ColumnModel1" runat="server" >
                            <Columns>
                                <ext:RowNumbererColumn />
                                <ext:Column ColumnID="QuotationDetailId" DataIndex="QuotationDetailId" Header="QuotationDetailId" />
                                <ext:Column ColumnID="QuotationId" DataIndex="QuotationId" Header="QuotationId" />
                                <ext:Column ColumnID="ProductId" DataIndex="ProductId" Header="ProductId">
                                </ext:Column>
                                <ext:Column ColumnID="UnitId" DataIndex="UnitId" Header="UnitId" />
                                <ext:Column ColumnID="UnitPrice" DataIndex="UnitPrice" Header="UnitPrice" />
                                <ext:Column ColumnID="Deleted" DataIndex="Deleted" Header="Deleted" />
                                <ext:Column ColumnID="CreatedDate" DataIndex="CreatedDate" Header="CreatedDate" />
                                <ext:Column ColumnID="CreatedBy" DataIndex="CreatedBy" Header="CreatedBy" />
                                <ext:Column ColumnID="UpdatedDate" DataIndex="UpdatedDate" Header="UpdatedDate" />
                                <ext:Column ColumnID="UpdatedBy" DataIndex="UpdatedBy" Header="UpdatedBy" />
                            </Columns>
                        </ColumnModel>
                        <BottomBar>
                            <ext:PagingToolbar ID="paddingBar" StoreID="storeQuotationDetail" runat="server" PageSize="50"
                                DisplayInfo="true" DisplayMsg="Đang xem dòng {0} đến {1} của {2}" EmptyMsg="Không có dữ liệu">
                            </ext:PagingToolbar>
                        </BottomBar>
                    </ext:GridPanel>
                </Items>
            </ext:Panel>--%>
            <%--      <ext:GridPanel ID="GridPanel1" runat="server" Region="Center">
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column Header="Test" DataIndex="test">
                            <Editor>
                                <ext:ComboBox ID="ComboBox1" runat="server" ListWidth="300" StoreID="storeProduct" ValueField="ProductId" DisplayField="ProductName">
                                    
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>--%>
            <ext:GridPanel ID="GridPanel1" runat="server" Width="600" Height="400" AutoExpandColumn="ProductId"
                Region="Center" StoreID="storeQuotationDetail">
                <Plugins>
                    <ext:RowEditor ID="RowEditor1" runat="server" SaveText="Cập nhật" CancelText="Đóng" />
                </Plugins>
                <View>
                    <ext:GridView ID="GridView1" runat="server" MarkDirty="false" />
                </View>
                <TopBar>
                    <ext:Toolbar ID="Toolbar2" runat="server">
                        <Items>
                            <ext:Button ID="Button1" runat="server" Icon="Add">
                                <Listeners>
                                    <Click Fn="add" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button2" runat="server" Icon="Delete">
                                <Listeners>
                                    <Click Fn="remove" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <ColumnModel>
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="ProductId" Header="ProductId" DataIndex="ProductId" Width="220"
                            Sortable="true">
                            <Editor>
                                <ext:ComboBox ID="ComboBox1" runat="server" StoreID="storeProduct" DisplayField="ProductName"
                                    ValueField="ProductId">
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="UnitId" DataIndex="UnitId" Width="150">
                            <Editor>
                                <ext:TextField ID="TextField2" runat="server" />
                            </Editor>
                        </ext:Column>
                        <ext:NumberColumn Header="UnitPrice" DataIndex="UnitPrice" Format="0.0,00" Width="100"
                            Sortable="true">
                            <Editor>
                                <ext:NumberField ID="NumberField1" runat="server" MinValue="1" MaxValue="999999999" />
                            </Editor>
                        </ext:NumberColumn>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
